package org.vectrics.recruiter.struts.tag;

import org.apache.ecs.html.A;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;
import org.vectrics.common.pagelist.PageList;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.user.resume.email.EmailedResumeCriteria;
import org.vectrics.recruiter.user.resume.email.EmailedResumeInfo;
import org.vectrics.struts.PageListTableTag;

public class EmailedResumePageListTag extends PageListTableTag {

	private static final long serialVersionUID = 5377214632036464230L;
	
	private String showUnfinished = "true";
    private String showProcessed = "false";
    private String showDisposed = "false";

	public EmailedResumePageListTag() {
		super();
	}

	protected String getTableWidth() {
		return("95%");
	}

	protected void renderHeaderRow(Row headerRow) {
        headerRow.setDefaultCellFontClass("tableHdrFont");
		headerRow.addCell().addText(this.getPhrase("prompt.email.from.address"));
		headerRow.addCell().addText(this.getPhrase("prompt.email.from.name"));
		headerRow.addCell().addText(this.getPhrase("prompt.email.subject"));
		headerRow.addCell().addText(this.getPhrase("prompt.email.date.received"));
		headerRow.addCell().addText(this.getPhrase("prompt.email.status"));
		headerRow.addCell().addText("");
	}
	
	protected void renderDataRow(Row dataRow, Object element) {
		EmailedResumeInfo info = (EmailedResumeInfo)element;
		Cell cell = dataRow.addCell();
		cell.addText(info.getFromEmailAddress());

		cell = dataRow.addCell();
		cell.addText(info.getFromEmailName());

		cell = dataRow.addCell();
		cell.addText(info.getEmailSubject());

		cell = dataRow.addCell();
		cell.addText(CoreServiceLocator.getDateFormat().getDateFormatRoundToMinute(this.getLocale()).format(info.getDateSent()));

		cell = dataRow.addCell();
		cell.addText(info.getStatusCode());

		cell = dataRow.addCell();
		A link = new A();
		link.setClass("subLink");
		link.setHref(this.getContextPath() + "/admin/jobs/emailedResumes/view.do?emailedResumeId=" + info.getId());
		link.addElement(this.getPhrase("phrase.view"));
		cell.addElement(link);
		
		
	}
	
	protected String getDescription() {
		return null;
	}

	protected String getPageListLink() {
		return "/hrs-intranet/admin/jobs/emailedResumes.do";
	}


	protected PageList createPageList() {
		EmailedResumeCriteria criteria = new EmailedResumeCriteria();
		if (this.showUnfinished.equals("true")) {
			criteria.addStatus(EmailedResumeInfo.STATUS_NEW);
			criteria.addStatus(EmailedResumeInfo.STATUS_PARTIAL_PROCESSED);
		}
		if (this.showProcessed.equals("true")) {
			criteria.addStatus(EmailedResumeInfo.STATUS_PROCESSED);
		}
		if (this.showDisposed.equals("true")) {
			criteria.addStatus(EmailedResumeInfo.STATUS_DISPOSED);
		}
		EmailedResumePageList pageList = new EmailedResumePageList(criteria);
		return pageList;
	}

	/**
	 * @return Returns the showProcessed.
	 */
	public String getShowProcessed() {
		return showProcessed;
	}

	/**
	 * @param showProcessed The showProcessed to set.
	 */
	public void setShowProcessed(String showProcessed) {
		this.showProcessed = showProcessed;
	}

	/**
	 * @return Returns the showUnfinished.
	 */
	public String getShowUnfinished() {
		return showUnfinished;
	}

	/**
	 * @param showUnfinished The showUnfinished to set.
	 */
	public void setShowUnfinished(String showUnfinished) {
		this.showUnfinished = showUnfinished;
	}

	/**
	 * @return Returns the showDisposed.
	 */
	public String getShowDisposed() {
		return showDisposed;
	}

	/**
	 * @param showDisposed The showDisposed to set.
	 */
	public void setShowDisposed(String showDisposed) {
		this.showDisposed = showDisposed;
	}

	
	
}
